﻿// //  ********************************************************************************
// //  Copyright (C) 2016 Sebastian Kenter. All rights reserved.
// // 
// //  Name    : PhotonServerProject | PhotonServerFramework | IServerApplication.cs
// //  Created : 2016 - 03 - 21 09:51
// //  Modified: 2016 - 04 - 18 09:38
// //  ********************************************************************************

using System;
using ExitGames.Logging;
using PhotonServerCommon.Enums;
using PhotonServerFramework.Interfaces.Configuration;

namespace PhotonServerFramework.Interfaces.Application
{
    /// <summary>
    ///     Interface for the server application (modules) that get created by the photon server instances
    /// </summary>
    public interface IServerApplication
    {
        /// <summary>
        ///     Logger instance
        /// </summary>
        ILogger Logger { get; }

        /// <summary>
        ///     Server configuration loaded from the database
        /// </summary>
        IServerConfiguration Configuration { get; }

        /// <summary>
        ///     Unique server id, inherited from the server instance
        /// </summary>
        Guid ServerId { get; }

        /// <summary>
        ///     The type of the server (e.g. MasterServer, LoginServer, RealmServer ...)
        /// </summary>
        ServerTypes ServerType { get; }

        /// <summary>
        ///     Everything that need to be setup goes here like handler registration
        /// </summary>
        void Setup();

        /// <summary>
        ///     Everything that need to be cleaned up before the server stops goes here
        /// </summary>
        void OnStopRequested();

        /// <summary>
        ///     Last line of defense before the server instance is teared down finally
        /// </summary>
        void TearDown();

        /// <summary>
        ///     In case of a connection error the response comes in here. Uses for automatic reconnection
        /// </summary>
        /// <param name="errorCode">The Photon error code</param>
        /// <param name="errorMessage">The Photon error message if provided</param>
        /// <param name="state">
        ///     Some state object (filled by the
        ///     <see cref="P:Photon.SocketServer.ApplicationBase.ConnectToServerTcp" />)
        /// </param>
        void OnServerConnectionFailed(int errorCode, string errorMessage, object state);
    }
}
